package gui.settings;


import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LaunchAlsSettings extends JPanel {
	private static final long serialVersionUID = 1L;

	JSlider slider;
	JLabel label;
	JTextField text;

	public LaunchAlsSettings() {
		//JFrame frame = new JFrame("Slider Frame");
		JLabel label2 = new JLabel("Launch ignition retard");    
		slider = new JSlider();

		slider.setValue(70);
		slider.addChangeListener(new MyChangeAction());
		//label = new JLabel(slider.getValue()+"");
		text = new JTextField(4);
		text.setText(slider.getValue()+"");
		// JPanel panel = new JPanel();
		add(label2);
		add(slider);
		//add(label);
		add(text);


		text.addActionListener(new ActionListener() {    
			@Override
			public void actionPerformed(ActionEvent e) {
				try
				{
					slider.setValue(Integer.parseInt(text.getText()));
				}
				catch(Exception ex)
				{
					text.setText("ERROR");
					text.setToolTipText("Set Value in Range between 0 - 1000 ") ;
				}
			}
		});


	}

	public class MyChangeAction implements ChangeListener{
		public void stateChanged(ChangeEvent ce){
			int value = slider.getValue();
			String str = Integer.toString(value);
			text.setText(str);
		}
	}





}

